<!DOCTYPE html>
<html>
<head>
    <title>Required Field Example</title>
    <script type="text/javascript" src="EventUtil.js"></script>
</head>
<body>
    <p>Try submitting the following form without filling in a value for the textbox. This only works in HTML5-compliant browsers.</p>
    <script>
        (function(){
            var message = "Your browser does not support required form fields.";
            if ("required" in document.createElement("input")){
                message = "Your browser supports required form fields!";
            }
            document.write("<p>" + message + "</p>");
            
        })();
    </script>
    <form method="post" action="javascript:alert('Form submitted!')" id="myForm">
        <label for="username">Username:</label> <input type="text" name="username" id="username" required>
        <input type="submit" value="Submit Form"><br>
        <input type="button" value="Check Validity" id="btnCheck"><input type="button" value="Will Validate?" id="btnWill">
    </form>
    <script>
        EventUtil.addHandler(document.getElementById("btnCheck"), "click", function(event){
            alert(document.forms[0].elements[0].checkValidity());
        });    
        EventUtil.addHandler(document.getElementById("btnWill"), "click", function(event){
            alert(document.forms[0].elements[0].willValidate);
        });    
    </script>
</body>
</html>
